package dlg.code.state.context.service;

import dlg.code.state.context.service.impl.AfterDeliveredReminderService;
import dlg.code.state.context.service.impl.AfterPaidReminderService;
import dlg.code.state.domain.OrderInfo;
import dlg.code.state.enums.OrderStateEnum;
import dlg.code.state.enums.ReminderStageEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.ConcurrentHashMap;

public abstract class AbstractOrderStateService implements IOrderStateService {
    private final static Logger log = LoggerFactory.getLogger(AbstractOrderStateService.class);

    private final static ConcurrentHashMap<ReminderStageEnum, IReminderService> reminderMap = new ConcurrentHashMap<>();

    static {
        reminderMap.put(ReminderStageEnum.AFTER_PAID, new AfterPaidReminderService());
        reminderMap.put(ReminderStageEnum.AFTER_DELIVERED, new AfterDeliveredReminderService());
    }

    protected OrderStateEnum orderStateEnum;

    @Override
    public boolean pay(OrderInfo orderInfo) {
        log.info("pay操作无法执行");
        return false;
    }

    @Override
    public boolean reminder(OrderInfo orderInfo) {
        log.info("reminder操作无法执行");
        return false;
    }

    @Override
    public boolean delete(OrderInfo orderInfo) {
        log.info("delete操作无法执行");
        return false;
    }

    @Override
    public void changeState(OrderInfo orderInfo, OrderStateEnum orderStateEnum) {
        log.info("changeState操作无法执行");
    }

    public OrderStateEnum getOrderStateEnum() {
        return orderStateEnum;
    }

    public IReminderService getReminderService(ReminderStageEnum reminderStageEnum) {
        IReminderService reminderService = reminderMap.get(reminderStageEnum);
        if (reminderService == null) {
            throw new IllegalArgumentException("催单操作异常：" + reminderStageEnum.getName());
        }
        return reminderService;
    }
}
